Cleanup remotefile resolver and delete internal/worker#2178
Cleanup remotefile resolver and delete internal/worker#2178lzap wants to merge 10 commits intoosbuild:mainfrom
Conversation
thozza
left a comment
There was a problem hiding this comment.
Thanks for taking this on. All the enhancements make sense, but I don't like the change to make the test cope with indeterminism when the results are actually deterministic.
461c735 to
2930004
Compare
|
Dropped the unnecessary test change. Renamed Added one new commit that adds HTTP client as an optional argument. This is new but now that I look on it this can be also added later without breaking the API so I can drop this one. |
2930004 to
85fff07
Compare
|
Yeah good catch, I meant to do this but forgot. Modified one test to accommodate for the change. Rebased. |
thozza
left a comment
There was a problem hiding this comment.
I've added some nitpicks, but I won't bother you further.
Also, I really like the use of the functional options pattern. It looks great ❤️
The remotefile package provides a content resolver implementation, not a customization. Move it to the pkg/ directory, where also other content resolver packages live. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
Rework the remotefile resolver to not embed the resolution error in the Spec definition, but instead return error from the resolver `Finish()` method. This is consistent with i.e. the container resolver. Additionally, don't use clienterrors package for errors. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This is a leftover from osbuild-composer split, while the authoritative copy still lives in osbuild-composer repository. The package is not needed in the images library.
To ensure deterministic error messages, sort the error messages before returning them and then remove consecutive duplicate error messages (which are unlikely but the call is cheap).
Previously, the context was completely unused. Let's use it to ensure that possible deadlines are respected.
85fff07 to
54e643d
Compare
|
Agreed on test and your point actually revealed that I accidentally implemented Added new commit that solves this: |
thozza
left a comment
There was a problem hiding this comment.
The code looks OK, but now I feel like the patch set became a spaghetti monster. Given that you've added new commits multiple times and there was not that much code to review and too many reviews, I would advice to squash changes that are basically fixups, with the original commits. I feel like this is a bit of a mess now.
Previously, the resolver was not concurrent safe. Let's make it so that multiple calls to Add and Finish can be made concurrently.
The results are being collected via a buffered channel which has a small size of 2. Collecting of results is very efficient compared to HTTP calls, therefore the chance that the channel will block is very low. While 2 will definitely not hurt, I find it confusing because the name of the field is "queue" which made me think of a queue of items to be processed. That is not the case here, it is queue of results.
These error codes were silently ignored.
I was a bit confused when I saw the queue, together with the buffered channel I made a wrong assumption.
This allows users to provide their own HTTP client implementation, such as a custom transport or timeout.
54e643d to
ce356b3
Compare
|
Squashed two commit pairs, so from 12 there are 10 commits. I think the rest is worth keeping separate. |
|
Since you already commented in the original PR, @achilleas-k cheers! |
This builds on top of #1957 and fixes tests. On top of that, it adds a bunch of small improvements which are rather insignificant but nice to have.
This all is needed in order to use the (currently unused) resolver for GPG keys: osbuild/osbuild#2326
Additionally, once this is merged we should make use of it in composer, there seems to be a copy of this functionality:
https://github.com/osbuild/osbuild-composer/tree/main/internal/remotefile
The randomness in tests is solved in two commits, both will work or just one of them too (sort errors or just accept they come in random order).
Context was present but never used.
Then the code was not thread safe, but it is likely only used from one goroutine so it was never a problem. But I think using wait groups is actually nicer code.
What was undocumented was that call of
AddafterFinishwould cause panic, I think it is fair to just document that and live with it. Any solution will make the code less readable than it can be and we do not need that robustness. Honestly, the way this is implemented is very simplistic and could be improved but this is not something we need today.Then I dropped the buffering from the channel, this has no effect and it makes the code a bit confusing. Discuss, I can drop this if you feel strong about this.
Finally, the HTTP error codes were not handled so this would silently create empty files. I am not sure if this was desired behavior, can drop if it was.
I do have some other ideas in mind to further improve this, but I wanted to keep things simple. But just in case:
NewResolver. This usually makes testing easier, setting timeouts or TLS possible.